package com.gaodun.luffy;

public class Template {

    public static String CreateDemoDTO = "package com.gaodun.luffy.template;\n" +
            "\n" +
            "import com.gaodun.luffy.integration.fegin.dto.PageQueryDTO;\n" +
            "import io.swagger.annotations.ApiModel;\n" +
            "import io.swagger.annotations.ApiModelProperty;\n" +
            "import lombok.AllArgsConstructor;\n" +
            "import lombok.Builder;\n" +
            "import lombok.Data;\n" +
            "import lombok.NoArgsConstructor;\n" +
            "\n" +
            "import java.io.Serializable;\n" +
            "import java.util.List;\n" +
            "\n" +
            "\n" +
            "@Data\n" +
            "@Builder\n" +
            "@AllArgsConstructor\n" +
            "@NoArgsConstructor\n" +
            "@ApiModel(description = \"创建示例配置\")\n" +
            "public class CreateDemoDTO extends PageQueryDTO implements Serializable {\n" +
            "\n" +
            "    private static final long serialVersionUID = -1L;\n" +
            "\n" +
            "\n" +
            "    //下面是表对应字段 去除创建更新时间和isDelete字段-----------------------------------------------------------------------------------------------\n" +
            "\n" +
            "\n" +
            "    /**\n" +
            "     * 主键ID\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"id\")\n" +
            "    private Integer id;\n" +
            "\n" +
            "    /**\n" +
            "     * 名称\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"名称\")\n" +
            "    private String name;\n" +
            "\n" +
            "    /**\n" +
            "     * 启用/禁用\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"启用/禁用\")\n" +
            "    private Integer isEnable;\n" +
            "\n" +
            "    /**\n" +
            "     * 项目id\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"项目id\")\n" +
            "    private Integer projectId;\n" +
            "\n" +
            "    //下面是列表查询条件-----------------------------------------------------------------------------------------------\n" +
            "\n" +
            "    /**\n" +
            "     * 项目id集合\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"项目id集合\")\n" +
            "    private List<Integer> projectIdList;\n" +
            "\n" +
            "    /**\n" +
            "     * 明细列表\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"明细列表\")\n" +
            "    private List<CreateDemoDetailDTO> list;\n" +
            "\n" +
            "\n" +
            "}";


    public static String CreateDemoDetailDTO ="package com.gaodun.luffy.template;\n" +
            "\n" +
            "import com.gaodun.luffy.integration.fegin.dto.PageQueryDTO;\n" +
            "import io.swagger.annotations.ApiModel;\n" +
            "import io.swagger.annotations.ApiModelProperty;\n" +
            "import lombok.AllArgsConstructor;\n" +
            "import lombok.Builder;\n" +
            "import lombok.Data;\n" +
            "import lombok.NoArgsConstructor;\n" +
            "\n" +
            "import java.io.Serializable;\n" +
            "\n" +
            "@Data\n" +
            "@Builder\n" +
            "@AllArgsConstructor\n" +
            "@NoArgsConstructor\n" +
            "@ApiModel(description = \"创建示例明细配置\")\n" +
            "public class CreateDemoDetailDTO extends PageQueryDTO implements Serializable {\n" +
            "\n" +
            "    private static final long serialVersionUID = -1L;\n" +
            "\n" +
            "    //下面是表对应字段 去除创建更新时间和isDelete字段----------------------------------------------------------------------------------------\n" +
            "    /**\n" +
            "     * 主键ID\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"id\")\n" +
            "    private Integer id;\n" +
            "\n" +
            "\n" +
            "    //-----------------------------------------------------------------------------------------------------------------------\n" +
            "\n" +
            "    /**\n" +
            "     * 名称\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"名称\")\n" +
            "    private String name;\n" +
            "\n" +
            "}";

    public static String CreateDemoDetailHandler ="package com.gaodun.luffy.template;\n" +
            "\n" +
            "import com.gaodun.luffy.domain.TKHandler;\n" +
            "import com.gaodun.luffy.template.done.CreateDemo;\n" +
            "import com.gaodun.luffy.template.done.CreateDemoDetail;\n" +
            "import com.gaodun.luffy.template.done.CreateDemoDetailMapper;\n" +
            "import com.gaodun.luffy.template.done.CreateDemoMapper;\n" +
            "import org.apache.commons.collections.CollectionUtils;\n" +
            "import org.springframework.stereotype.Service;\n" +
            "import tk.mybatis.mapper.entity.Example;\n" +
            "import tk.mybatis.mapper.weekend.Weekend;\n" +
            "import tk.mybatis.mapper.weekend.WeekendCriteria;\n" +
            "\n" +
            "import javax.annotation.Resource;\n" +
            "import java.util.ArrayList;\n" +
            "import java.util.List;\n" +
            "import java.util.Objects;\n" +
            "\n" +
            "/**\n" +
            " * @author fengyamin\n" +
            " * @date 2022年07月04日 11:19\n" +
            " * @desc\n" +
            " */\n" +
            "@Service\n" +
            "public class CreateDemoDetailHandler extends TKHandler<CreateDemoDetailMapper, CreateDemoDetail> {\n" +
            "\n" +
            "    public List<CreateDemoDetail> selectListByCreateDemoId(Integer createDemoId) {\n" +
            "        Weekend<CreateDemoDetail> weekend = Weekend.of(CreateDemoDetail.class, true, true);\n" +
            "        WeekendCriteria<CreateDemoDetail, Object> weekendCriteria = weekend.weekendCriteria();\n" +
            "        //TODO 记得使用参数  weekendCriteria.andEqualTo(CreateDemoDetail::getActivityGroupId, createDemoId);\n" +
            "        weekendCriteria.andEqualTo(CreateDemoDetail::getIsDelete, 0);\n" +
            "        return baseMapper.selectByExample(weekend);\n" +
            "    }\n" +
            "\n" +
            "\n" +
            "    public void deleteByIdList(List<Integer> idList) {\n" +
            "        if (CollectionUtils.isNotEmpty(idList)) {\n" +
            "            //TODO 逻辑删除\n" +
            "            List<CreateDemoDetail> deleteList = new ArrayList<>();\n" +
            "            for (Integer id : idList) {\n" +
            "                deleteList.add(CreateDemoDetail.builder().id(id).isDelete(1).build());\n" +
            "            }\n" +
            "            batchUpdateSelective(deleteList);\n" +
            "\n" +
            "            //TODO 物理删除\n" +
            "            deleteByIds(idList);\n" +
            "        }\n" +
            "    }\n" +
            "\n" +
            "\n" +
            "    public void deleteByCreateDemoId(Integer createDemoId) {\n" +
            "        Weekend<CreateDemoDetail> weekend = Weekend.of(CreateDemoDetail.class, true, true);\n" +
            "        weekend.createCriteria().andEqualTo(\"createDemoId\", createDemoId);\n" +
            "        baseMapper.deleteByExample(weekend);\n" +
            "    }\n" +
            "}\n";
    public static String CreateDemoEndpoint ="package com.gaodun.luffy.template;\n" +
            "\n" +
            "import com.gaodun.luffy.common.utils.LoginUtils;\n" +
            "import com.github.pagehelper.PageInfo;\n" +
            "import io.swagger.annotations.Api;\n" +
            "import io.swagger.annotations.ApiOperation;\n" +
            "import lombok.extern.slf4j.Slf4j;\n" +
            "import org.springframework.web.bind.annotation.*;\n" +
            "import com.gaodun.luffy.template.CreateDemoService;\n" +
            "import com.gaodun.luffy.template.CreateDemoDTO;\n" +
            "import com.gaodun.luffy.template.CreateDemoWebVO;\n" +
            "\n" +
            "import javax.annotation.Resource;\n" +
            "\n" +
            "\n" +
            "/**\n" +
            " * @author fengyamin\n" +
            " * @date 2024/2/11\n" +
            " **/\n" +
            "\n" +
            "@Slf4j\n" +
            "@RestController\n" +
            "@RequestMapping(\"/v1/api/createDemo\")\n" +
            "@Api(tags = {\"B-创建示例配置\"})\n" +
            "public class CreateDemoEndpoint {\n" +
            "\n" +
            "    @Resource\n" +
            "    private CreateDemoService createDemoService;\n" +
            "\n" +
            "\n" +
            "    @PostMapping(\"/create\")\n" +
            "    @ApiOperation(value = \"新增创建示例\", notes = \"新增创建示例\")\n" +
            "    public Integer create(@RequestBody CreateDemoDTO createDemoDTO) {\n" +
            "        return createDemoService.create(createDemoDTO, LoginUtils.getLoginUserId());\n" +
            "    }\n" +
            "\n" +
            "    @PostMapping(\"/update\")\n" +
            "    @ApiOperation(value = \"更新创建示例\", notes = \"更新创建示例\")\n" +
            "    public void update(@RequestBody CreateDemoDTO createDemoDTO) {\n" +
            "        createDemoService.update(createDemoDTO, LoginUtils.getLoginUserId());\n" +
            "    }\n" +
            "\n" +
            "    @PostMapping(\"/list\")\n" +
            "    @ApiOperation(value = \"创建示例列表\", notes = \"创建示例列表\")\n" +
            "    public PageInfo<CreateDemoWebVO> list(@RequestBody CreateDemoDTO createDemoDTO) {\n" +
            "        return createDemoService.list(createDemoDTO);\n" +
            "    }\n" +
            "\n" +
            "    @GetMapping(\"/detail\")\n" +
            "    @ApiOperation(value = \"创建示例详情\", notes = \"创建示例详情\")\n" +
            "    public CreateDemoDTO detail(Integer id) {\n" +
            "        return createDemoService.detail(id);\n" +
            "    }\n" +
            "\n" +
            "    @PostMapping(\"/enable\")\n" +
            "    @ApiOperation(value = \"启用创建示例\", notes = \"启用创建示例\")\n" +
            "    public void enable(@RequestBody CreateDemoDTO createDemoDTO) {\n" +
            "        createDemoService.enable(createDemoDTO, LoginUtils.getLoginUserId());\n" +
            "    }\n" +
            "\n" +
            "    @PostMapping(\"/delete\")\n" +
            "    @ApiOperation(value = \"删除\", notes = \"删除\")\n" +
            "    public void delete(Integer id) {\n" +
            "        createDemoService.delete(id, LoginUtils.getLoginUserId());\n" +
            "    }\n" +
            "}\n";
    public static String CreateDemoHandler ="package com.gaodun.luffy.template;\n" +
            "\n" +
            "import cn.hutool.core.collection.CollUtil;\n" +
            "import com.gaodun.luffy.common.enums.IsEnableEnum;\n" +
            "import com.gaodun.luffy.domain.TKHandler;\n" +
            "import com.gaodun.luffy.template.done.CreateDemo;\n" +
            "import com.gaodun.luffy.template.done.CreateDemoMapper;\n" +
            "import org.springframework.stereotype.Service;\n" +
            "import tk.mybatis.mapper.weekend.Weekend;\n" +
            "import tk.mybatis.mapper.weekend.WeekendCriteria;\n" +
            "import com.gaodun.luffy.template.CreateDemoDTO;\n" +
            "import com.gaodun.luffy.template.CreateDemoWebVO;\n" +
            "\n" +
            "import java.util.List;\n" +
            "import java.util.Objects;\n" +
            "\n" +
            "/**\n" +
            " * @author fengyamin\n" +
            " * @date 2022年07月04日 11:19\n" +
            " * @desc\n" +
            " */\n" +
            "@Service\n" +
            "public class CreateDemoHandler extends TKHandler<CreateDemoMapper, CreateDemo> {\n" +
            "\n" +
            "\n" +
            "    public List<CreateDemo> selectListByParam(Integer projectId, String name) {\n" +
            "        //TODO 查询东西不一样\n" +
            "        Weekend<CreateDemo> weekend = Weekend.of(CreateDemo.class, true, true);\n" +
            "        WeekendCriteria<CreateDemo, Object> weekendCriteria = weekend.weekendCriteria();\n" +
            "        weekendCriteria.andEqualTo(CreateDemo::getIsDelete, 0);\n" +
            "        if (Objects.nonNull(projectId)) {\n" +
            "            weekendCriteria.andEqualTo(CreateDemo::getProjectId, projectId);\n" +
            "        }\n" +
            "        //可以根据多个字段排序\n" +
            "        weekend.orderBy(\"id\").asc().orderBy(\"id\").desc();\n" +
            "        return baseMapper.selectByExample(weekend);\n" +
            "    }\n" +
            "\n" +
            "    public Integer insert(CreateDemo createDemo, Integer userId) {\n" +
            "        createDemo.setCreatedBy(userId);\n" +
            "        createDemo.setUpdatedBy(userId);\n" +
            "        //TODO 默认启用 createDemo.setIsEnable(IsEnableEnum.ENABLE.getValue());\n" +
            "        baseMapper.insertSelective(createDemo);\n" +
            "        return createDemo.getId();\n" +
            "    }\n" +
            "\n" +
            "\n" +
            "    public void update(CreateDemo createDemo, Integer userId) {\n" +
            "        //TODO 改名字别和tk重复引起错用 where id= and version=\n" +
            "        createDemo.setUpdatedBy(userId);\n" +
            "        baseMapper.updateByPrimaryKeySelective(createDemo);\n" +
            "    }\n" +
            "\n" +
            "    public void enable(Integer id,Integer isEnable, Integer userId) {\n" +
            "        CreateDemo build = CreateDemo.builder().id(id).updatedBy(userId).build();\n" +
            "        //TODO 启用字段\n" +
            "        //build.setIsEnable(isEnable);\n" +
            "        baseMapper.updateByPrimaryKeySelective(build);\n" +
            "    }\n" +
            "\n" +
            "    // TODO  xml分页列表使用\n" +
            "    /*public List<CreateDemoWebVO> list(CreateDemoDTO dto) {\n" +
            "        return baseMapper.list(dto);\n" +
            "    }*/\n" +
            "\n" +
            "\n" +
            "    public List<CreateDemo> pageList(CreateDemoDTO dto) {\n" +
            "        Weekend<CreateDemo> weekend = Weekend.of(CreateDemo.class, true, true);\n" +
            "        WeekendCriteria<CreateDemo, Object> weekendCriteria = weekend.weekendCriteria();\n" +
            "        weekendCriteria.andEqualTo(CreateDemo::getIsDelete, 0);\n" +
            "        //TODO 查询东西不一样\n" +
            "        if (CollUtil.isNotEmpty(dto.getProjectIdList())) {\n" +
            "            weekendCriteria.andIn(CreateDemo::getProjectId, dto.getProjectIdList());\n" +
            "        }\n" +
            "        weekend.orderBy(\"id\").desc();\n" +
            "        return baseMapper.selectByExample(weekend);\n" +
            "    }\n" +
            "}\n";
    public static String CreateDemoService ="package com.gaodun.luffy.template;\n" +
            "\n" +
            "import com.github.pagehelper.PageInfo;\n" +
            "import com.gaodun.luffy.template.CreateDemoDTO;\n" +
            "import com.gaodun.luffy.template.CreateDemoWebVO;\n" +
            "\n" +
            "/**\n" +
            " * @author fengyamin\n" +
            " * @date 2022年07月04日 11:22\n" +
            " * @desc\n" +
            " */\n" +
            "public interface CreateDemoService {\n" +
            "\n" +
            "    /**\n" +
            "     * 创建创建示例\n" +
            "     *\n" +
            "     * @param dto\n" +
            "     * @param userId\n" +
            "     */\n" +
            "    Integer create(CreateDemoDTO dto, Integer userId);\n" +
            "\n" +
            "    /**\n" +
            "     * 创建示例详情\n" +
            "     *\n" +
            "     * @param id\n" +
            "     * @return\n" +
            "     */\n" +
            "    CreateDemoDTO detail(Integer id);\n" +
            "\n" +
            "    /**\n" +
            "     * 更新创建示例\n" +
            "     *\n" +
            "     * @param dto\n" +
            "     * @param userId\n" +
            "     */\n" +
            "    void update(CreateDemoDTO dto, Integer userId);\n" +
            "\n" +
            "    /**\n" +
            "     * 启用禁用创建示例\n" +
            "     *\n" +
            "     * @param dto\n" +
            "     * @param userId\n" +
            "     */\n" +
            "    void enable(CreateDemoDTO dto, Integer userId);\n" +
            "\n" +
            "    /**\n" +
            "     * 创建示例列表\n" +
            "     *\n" +
            "     * @param dto\n" +
            "     * @return\n" +
            "     */\n" +
            "    PageInfo<CreateDemoWebVO> list(CreateDemoDTO dto);\n" +
            "\n" +
            "\n" +
            "    /**\n" +
            "     * 删除\n" +
            "     *\n" +
            "     * @param id\n" +
            "     * @param loginUserId\n" +
            "     */\n" +
            "    void delete(Integer id, Integer loginUserId);\n" +
            "\n" +
            "}\n";
    public static String CreateDemoServiceImpl ="package com.gaodun.luffy.template;\n" +
            "\n" +
            "import cn.hutool.core.collection.CollUtil;\n" +
            "import com.gaodun.luffy.common.exception.ServiceException;\n" +
            "import com.gaodun.luffy.common.utils.ModelMapperUtils;\n" +
            "import com.gaodun.luffy.common.utils.PageUtil;\n" +
            "import com.gaodun.luffy.integration.service.ViGoService;\n" +
            "import com.gaodun.luffy.service.permission.PermissionService;\n" +
            "import com.gaodun.luffy.template.done.CreateDemo;\n" +
            "import com.gaodun.luffy.template.done.CreateDemoDetail;\n" +
            "import com.github.pagehelper.PageHelper;\n" +
            "import com.github.pagehelper.PageInfo;\n" +
            "import lombok.extern.slf4j.Slf4j;\n" +
            "import org.apache.commons.collections.CollectionUtils;\n" +
            "import org.apache.commons.collections4.ListUtils;\n" +
            "import org.springframework.stereotype.Service;\n" +
            "import org.springframework.transaction.annotation.Transactional;\n" +
            "import com.gaodun.luffy.template.CreateDemoDTO;\n" +
            "import com.gaodun.luffy.template.CreateDemoDetailDTO;\n" +
            "import com.gaodun.luffy.template.CreateDemoWebVO;\n" +
            "import com.gaodun.luffy.template.CreateDemoHandler;\n" +
            "import com.gaodun.luffy.template.CreateDemoDetailHandler;\n" +
            "import com.gaodun.luffy.template.CreateDemoService;\n" +
            "\n" +
            "\n" +
            "\n" +
            "import javax.annotation.Resource;\n" +
            "import java.util.List;\n" +
            "import java.util.Map;\n" +
            "import java.util.Objects;\n" +
            "import java.util.stream.Collectors;\n" +
            "\n" +
            "/**\n" +
            " * @author fengyamin\n" +
            " * @date 2022年07月04日 11:22\n" +
            " * @desc\n" +
            " */\n" +
            "@Slf4j\n" +
            "@Service\n" +
            "public class CreateDemoServiceImpl implements CreateDemoService {\n" +
            "\n" +
            "    @Resource\n" +
            "    private PermissionService permissionService;\n" +
            "    @Resource\n" +
            "    private ViGoService viGoService;\n" +
            "    @Resource\n" +
            "    private CreateDemoHandler createDemoHandler;\n" +
            "    @Resource\n" +
            "    private CreateDemoDetailHandler createDemoDetailHandler;\n" +
            "\n" +
            "\n" +
            "    @Override\n" +
            "    @Transactional(rollbackFor = Exception.class)\n" +
            "    public Integer create(CreateDemoDTO dto, Integer userId) {\n" +
            "        permissionService.checkLoginUserProjectPermission(dto.getProjectId());\n" +
            "\n" +
            "        //TODO 校验不同\n" +
            "        List<CreateDemo> createDemos = createDemoHandler.selectListByParam(dto.getProjectId(), dto.getName());\n" +
            "        if (CollectionUtils.isNotEmpty(createDemos)) {\n" +
            "            throw ServiceException.newParamServiceException(\"同一项目下名称不能重复\");\n" +
            "        }\n" +
            "\n" +
            "        CreateDemo createDemo = ModelMapperUtils.map(dto, CreateDemo.class);\n" +
            "        Integer createDemoId = createDemoHandler.insert(createDemo, userId);\n" +
            "        saveList(dto.getList(), createDemoId, userId);\n" +
            "        return createDemoId;\n" +
            "    }\n" +
            "\n" +
            "\n" +
            "    /**\n" +
            "     * 保存子集合\n" +
            "     *\n" +
            "     * @param list\n" +
            "     * @param createDemoId\n" +
            "     * @param userId\n" +
            "     */\n" +
            "    private void saveList(List<CreateDemoDetailDTO> list, Integer createDemoId, Integer userId) {\n" +
            "        if (CollectionUtils.isEmpty(list)) {\n" +
            "            //TODO 删除所有\n" +
            "            createDemoDetailHandler.deleteByCreateDemoId(createDemoId);\n" +
            "            //return;\n" +
            "\n" +
            "            //TODO 提示语修改\n" +
            "            throw ServiceException.newParamServiceException(\"请至少配置一条信息\");\n" +
            "        }\n" +
            "        List<CreateDemoDetail> createDemoDetailOldList = createDemoDetailHandler.selectListByCreateDemoId(createDemoId);\n" +
            "        List<CreateDemoDetail> createDemoDetailNewList = ModelMapperUtils.mapList(list, CreateDemoDetail.class);\n" +
            "\n" +
            "        //取差集 删除被删除的\n" +
            "        List<Integer> oldIdList = createDemoDetailOldList.stream().map(CreateDemoDetail::getId).collect(Collectors.toList());\n" +
            "        List<Integer> newIdList = createDemoDetailNewList.stream().filter(x -> Objects.nonNull(x.getId())).map(CreateDemoDetail::getId).collect(Collectors.toList());\n" +
            "        List<Integer> difference = ListUtils.removeAll(oldIdList, newIdList);\n" +
            "        if (CollectionUtils.isNotEmpty(difference)) {\n" +
            "            createDemoDetailHandler.deleteByIdList(difference);\n" +
            "        }\n" +
            "\n" +
            "        //更新\n" +
            "        List<CreateDemoDetail> updateList = createDemoDetailNewList.stream().filter(x -> Objects.nonNull(x.getId())).collect(Collectors.toList());\n" +
            "        if (CollectionUtils.isNotEmpty(updateList)) {\n" +
            "            for (CreateDemoDetail createDemoDetail : updateList) {\n" +
            "                createDemoDetail.setUpdatedBy(userId);\n" +
            "            }\n" +
            "            createDemoDetailHandler.batchUpdateSelective(updateList);\n" +
            "        }\n" +
            "\n" +
            "        //新增\n" +
            "        List<CreateDemoDetail> addList = createDemoDetailNewList.stream().filter(x -> Objects.isNull(x.getId())).collect(Collectors.toList());\n" +
            "        if (CollectionUtils.isNotEmpty(addList)) {\n" +
            "            for (CreateDemoDetail createDemoDetail : addList) {\n" +
            "                //TODO 设置主表id\n" +
            "                createDemoDetail.setCreatedBy(userId);\n" +
            "                createDemoDetail.setUpdatedBy(userId);\n" +
            "            }\n" +
            "            createDemoDetailHandler.batchInsertSelective(addList);\n" +
            "        }\n" +
            "\n" +
            "    }\n" +
            "\n" +
            "    @Override\n" +
            "    public CreateDemoDTO detail(Integer id) {\n" +
            "        CreateDemo createDemo = createDemoHandler.selectByPrimaryKey(id);\n" +
            "        permissionService.checkLoginUserProjectPermission(createDemo.getProjectId());\n" +
            "        CreateDemoDTO createDemoDTO = ModelMapperUtils.map(createDemo, CreateDemoDTO.class);\n" +
            "        List<CreateDemoDetail> details = createDemoDetailHandler.selectListByCreateDemoId(createDemo.getId());\n" +
            "        createDemoDTO.setList(ModelMapperUtils.mapList(details, CreateDemoDetailDTO.class));\n" +
            "        return createDemoDTO;\n" +
            "    }\n" +
            "\n" +
            "    @Override\n" +
            "    @Transactional(rollbackFor = Exception.class)\n" +
            "    public void update(CreateDemoDTO dto, Integer userId) {\n" +
            "        permissionService.checkLoginUserProjectPermission(dto.getProjectId());\n" +
            "\n" +
            "        //TODO 校验不同\n" +
            "        List<CreateDemo> createDemos = createDemoHandler.selectListByParam(dto.getProjectId(), dto.getName());\n" +
            "        if (CollectionUtils.isNotEmpty(createDemos) && !dto.getId().equals(CollUtil.getFirst(createDemos).getId())) {\n" +
            "            throw ServiceException.newParamServiceException(\"同一项目下名称不能重复\");\n" +
            "        }\n" +
            "        CreateDemo createDemo = ModelMapperUtils.map(dto, CreateDemo.class);\n" +
            "        //TODO 防止ABA 加版本字段 自己重写update方法\n" +
            "        createDemoHandler.update(createDemo, userId);\n" +
            "\n" +
            "        saveList(dto.getList(), dto.getId(), userId);\n" +
            "    }\n" +
            "\n" +
            "    @Override\n" +
            "    public void enable(CreateDemoDTO dto, Integer userId) {\n" +
            "        CreateDemo createDemo = createDemoHandler.selectByPrimaryKey(dto.getId());\n" +
            "        permissionService.checkLoginUserProjectPermission(createDemo.getProjectId());\n" +
            "        createDemoHandler.enable(dto.getId(), dto.getIsEnable(), userId);\n" +
            "    }\n" +
            "\n" +
            "    @Override\n" +
            "    public PageInfo<CreateDemoWebVO> list(CreateDemoDTO dto) {\n" +
            "        dto.setProjectIdList(permissionService.handlerProjectIdList(dto.getProjectId()));\n" +
            "        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());\n" +
            "       /* List<CreateDemoWebVO> list = createDemoHandler.list(dto);\n" +
            "        PageInfo<CreateDemoWebVO> voPageInfo = new PageInfo<>(list);\n" +
            "        if (CollUtil.isEmpty(list)) {\n" +
            "            return voPageInfo;\n" +
            "        }\n" +
            "\n" +
            "        //创建人名称处理\n" +
            "        List<Integer> userIdList = list.stream().map(CreateDemoWebVO::getUpdatedBy).distinct().collect(Collectors.toList());\n" +
            "        Map<Integer, String> staffMsg = viGoService.getStaffFullNameMap(userIdList);\n" +
            "\n" +
            "        //TODO 其他字段枚举等批量查询\n" +
            "\n" +
            "        for (CreateDemoWebVO createDemoWebVO : list) {\n" +
            "            //TODO 其他字段设置名字等\n" +
            "            createDemoWebVO.setUpdatedByName(staffMsg.get(createDemoWebVO.getUpdatedBy()));\n" +
            "        }*/\n" +
            "\n" +
            "\n" +
            "        List<CreateDemo> list = createDemoHandler.pageList(dto);\n" +
            "        if (CollUtil.isEmpty(list)) {\n" +
            "            return new PageInfo<>();\n" +
            "        }\n" +
            "        List<CreateDemoWebVO> createDemoWebList = ModelMapperUtils.mapList(list, CreateDemoWebVO.class);\n" +
            "\n" +
            "        List<Integer> userIdList = list.stream().map(CreateDemo::getUpdatedBy).distinct().collect(Collectors.toList());\n" +
            "        Map<Integer, String> staffMsg = viGoService.getStaffFullNameMap(userIdList);\n" +
            "\n" +
            "        //TODO 其他字段枚举等批量查询\n" +
            "        for (CreateDemoWebVO createDemoWebVO : createDemoWebList) {\n" +
            "            //TODO 其他字段设置名字等\n" +
            "            createDemoWebVO.setUpdatedByName(staffMsg.get(createDemoWebVO.getUpdatedBy()));\n" +
            "        }\n" +
            "        return PageUtil.copy(list, createDemoWebList);\n" +
            "    }\n" +
            "\n" +
            "    /**\n" +
            "     * 删除\n" +
            "     *\n" +
            "     * @param id\n" +
            "     * @param loginUserId\n" +
            "     */\n" +
            "    @Override\n" +
            "    public void delete(Integer id, Integer loginUserId) {\n" +
            "        //TODO 物理删还是逻辑删\n" +
            "        //createDemoHandler.update(CreateDemo.builder().id(id).isDelete(1).build(), loginUserId);\n" +
            "        createDemoHandler.deleteByPrimaryKey(id);\n" +
            "    }\n" +
            "}\n";
    public static String CreateDemoWebVO ="package com.gaodun.luffy.template;\n" +
            "\n" +
            "import com.gaodun.luffy.integration.fegin.dto.PageQueryDTO;\n" +
            "import io.swagger.annotations.ApiModel;\n" +
            "import io.swagger.annotations.ApiModelProperty;\n" +
            "import lombok.AllArgsConstructor;\n" +
            "import lombok.Builder;\n" +
            "import lombok.Data;\n" +
            "import lombok.NoArgsConstructor;\n" +
            "\n" +
            "import java.io.Serializable;\n" +
            "import java.util.Date;\n" +
            "\n" +
            "\n" +
            "@Data\n" +
            "@Builder\n" +
            "@AllArgsConstructor\n" +
            "@NoArgsConstructor\n" +
            "@ApiModel(description = \"创建示例配置\")\n" +
            "public class CreateDemoWebVO extends PageQueryDTO implements Serializable {\n" +
            "\n" +
            "    private static final long serialVersionUID = -1L;\n" +
            "\n" +
            "    /**\n" +
            "     * 主键ID\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"id\")\n" +
            "    private Integer id;\n" +
            "\n" +
            "    /**\n" +
            "     * 项目id\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"项目id\")\n" +
            "    private Integer projectId;\n" +
            "\n" +
            "    /**\n" +
            "     * 名称\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"名称\")\n" +
            "    private String name;\n" +
            "\n" +
            "\n" +
            "    /**\n" +
            "     * 启用状态（0禁用 1启用）\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"启用状态（0禁用 1启用）\")\n" +
            "    private Integer isEnable;\n" +
            "\n" +
            "\n" +
            "    /**\n" +
            "     * 更新时间\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"更新时间\")\n" +
            "    private Date updatedAt;\n" +
            "\n" +
            "    /**\n" +
            "     * 更新人\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"更新人\")\n" +
            "    private Integer updatedBy;\n" +
            "\n" +
            "    /**\n" +
            "     * 更新人名称\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"更新人名称\")\n" +
            "    private String updatedByName;\n" +
            "\n" +
            "\n" +
            "    /**\n" +
            "     * 创建时间\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"创建时间\")\n" +
            "    private Date createdAt;\n" +
            "\n" +
            "    /**\n" +
            "     * 创建人\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"创建人\")\n" +
            "    private Integer createdBy;\n" +
            "\n" +
            "    /**\n" +
            "     * 创建人名称\n" +
            "     */\n" +
            "    @ApiModelProperty(value = \"创建人名称\")\n" +
            "    private String createdByName;\n" +
            "\n" +
            "}";
}
